<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/23
  Time: 10:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<html>
<head>
    <script src="<%=request.getContextPath()%>/js2/jquery.js"></script>
    <script src="<%=request.getContextPath()%>/js2/jquery.validate.min.js"></script>
    <script src="<%=request.getContextPath()%>/js2/messages_zh.js"></script>
    <script>
        $.validator.setDefaults({
            submitHandler: function () {
                var username=$("#username").val();
                var password=$("#password").val();
                alert(username+"==="+password);
                $.ajax({
                    url:"<%=basePath%>/Login",
                    type:"post",
                    data:{username:username, password:password},
                    dataType:"json",
                    success: function(data){
                        if(data==true){
                            window.location.href="index.jsp";
                        }else{
                            alert("用户名或密码错误");
                        }
                    }
                });
            }
        });
        $(document).ready(function(){
            $("#myForm").validate({
                 rules:{
                     username:{
                         required:true
                     },
                     password:{
                         required:true
                     }
                 },
                messages:{
                   username:{
                       required:"对不起，用户名不能为空"
                   } ,
                    password:{
                        required:"对不起，密码不能为空"
                    }
                }
            });
        });
    </script>
    <style>
        .error{
            color: red;
        }
    </style>
</head>
<body>

<form id="myForm">
   用户名：<input type="text" name="username" id="username"/><br>
   密码: <input type="password" name="password" id="password"/><br>
    <input type="submit" value="登录"/>
</form>
</body>
</html>
